package com.lijiaxing.controller;

import com.alibaba.fastjson.JSONObject;
import com.lijiaxing.pojo.Result;
import com.lijiaxing.pojo.UserRes;
import com.lijiaxing.service.menuService;
import com.lijiaxing.utils.JwtMaker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/menu")
public class menuController {
    @Autowired
    menuService ms;

    /**
     * @Description {获取用户权限}
     */
    @GetMapping("/permissions")
    public Result<String> getUserPermission(@RequestHeader("x-token") String token) {
        Map map = JwtMaker.deCoder(token);
        Object data = map.get("data");
        UserRes.User user = JSONObject.parseObject(data.toString(), UserRes.User.class);
        String userPermission = ms.getUserPermission(user.getPid());
        String route = "";
        switch (userPermission) {
            case "2,4,5":
                route ="{\"path\":\"/\",\"component\":\"Main\",\"name\":\"主页\",\"children\":[" +
                        "{\"path\":\"/auth\",\"name\":\"权限管理\","+
                        "\"index\":\"2\",\"icon\":\"Grid\",\"children\":[{\"path\":\"/auth/admin\"," +
                        "\"name\":\"账号管理\",\"index\":\"2-1\",\"icon\":\"Avatar\",\"component\":\"Admin\"" +
                        "}, {\"path\":\"/auth/group\",\"name\":\"菜单管理\"," +
                        "\"index\":\"2-2\",\"icon\":\"Menu\",\"component\":\"Group\"}" +
                        "]}]}";
                break;
            case "1,2,4,5":
                route = "{\"path\":\"/\",\"component\":\"Main\",\"name\":\"主页\",\"children\":[{\"" +
                        "path\":\"/dashboard\",\"name\":\"控制台\",\"index\":\"1\",\"icon\":\"Platform\"," +
                        "\"component\":\"Dashboard\"},{\"path\":\"/auth\",\"name\":\"权限管理\","+
                        "\"index\":\"2\",\"icon\":\"Grid\",\"children\":[{\"path\":\"/auth/admin\"," +
                        "\"name\":\"账号管理\",\"index\":\"2-1\",\"icon\":\"Avatar\",\"component\":\"Admin\"" +
                        "}, {\"path\":\"/auth/group\",\"name\":\"菜单管理\"," +
                        "\"index\":\"2-2\",\"icon\":\"Menu\",\"component\":\"Group\"}" +
                        "]}]}";
                break;
            case "1,2,4,5,6":
                route = "{\"path\":\"/\",\"component\":\"Main\",\"name\":\"主页\",\"children\":[{\"" +
                        "path\":\"/dashboard\",\"name\":\"控制台\",\"index\":\"1\",\"icon\":\"Platform\"," +
                        "\"component\":\"Dashboard\"},{\"path\":\"/auth\",\"name\":\"权限管理\","+
                        "\"index\":\"2\",\"icon\":\"Grid\",\"children\":[{\"path\":\"/auth/admin\"," +
                        "\"name\":\"账号管理\",\"index\":\"2-1\",\"icon\":\"Avatar\",\"component\":\"Admin\"" +
                        "}, {\"path\":\"/auth/group\",\"name\":\"菜单管理\"," +
                        "\"index\":\"2-2\",\"icon\":\"Menu\",\"component\":\"Group\"}" +
                        "]},{\"path\":\"vppz\",\"name\":\"陪诊管理\",\"index\":\"3\"," +
                        "\"icon\":\"BellFilled\",\"children\":[{\"path\":\"/vppz/staff\",\"name\":\"陪护管理\"," +
                        "\"index\":\"3-1\",\"icon\":\"Checked\",\"component\":\"Staff\"}" +
                        "]}]}";
                break;
            case "1,2,4,5,7":
                route = "{\"path\":\"/\",\"component\":\"Main\",\"name\":\"主页\",\"children\":[{\"" +
                        "path\":\"/dashboard\",\"name\":\"控制台\",\"index\":\"1\",\"icon\":\"Platform\"," +
                        "\"component\":\"Dashboard\"},{\"path\":\"/auth\",\"name\":\"权限管理\","+
                        "\"index\":\"2\",\"icon\":\"Grid\",\"children\":[{\"path\":\"/auth/admin\"," +
                        "\"name\":\"账号管理\",\"index\":\"2-1\",\"icon\":\"Avatar\",\"component\":\"Admin\"" +
                        "}, {\"path\":\"/auth/group\",\"name\":\"菜单管理\"," +
                        "\"index\":\"2-2\",\"icon\":\"Menu\",\"component\":\"Group\"}" +
                        "]},{\"path\":\"vppz\",\"name\":\"陪诊管理\",\"index\":\"3\"," +
                        "\"icon\":\"BellFilled\",\"children\":[{\"path\":\"/vppz/order\"," +
                        "\"name\":\"订单管理\",\"index\":\"3-1\",\"icon\":\"List\",\"component\":\"Order\"" +
                        "}" +
                        "]}]}";
                break;
            case "2,4,5,6":
                route = "{\"path\":\"/\",\"component\":\"Main\",\"name\":\"主页\",\"children\":[" +
                        "{\"path\":\"/auth\",\"name\":\"权限管理\","+
                        "\"index\":\"2\",\"icon\":\"Grid\",\"children\":[{\"path\":\"/auth/admin\"," +
                        "\"name\":\"账号管理\",\"index\":\"2-1\",\"icon\":\"Avatar\",\"component\":\"Admin\"" +
                        "}, {\"path\":\"/auth/group\",\"name\":\"菜单管理\"," +
                        "\"index\":\"2-2\",\"icon\":\"Menu\",\"component\":\"Group\"}" +
                        "]},{\"path\":\"vppz\",\"name\":\"陪诊管理\",\"index\":\"3\"," +
                        "\"icon\":\"BellFilled\",\"children\":[{\"path\":\"/vppz/staff\",\"name\":\"陪护管理\"," +
                        "\"index\":\"3-2\",\"icon\":\"Checked\",\"component\":\"Staff\"}" +
                        "]}]}";
                break;
            case "2,4,5,7":
                route = "{\"path\":\"/\",\"component\":\"Main\",\"name\":\"主页\",\"children\":[" +
                        "{\"path\":\"/auth\",\"name\":\"权限管理\","+
                        "\"index\":\"2\",\"icon\":\"Grid\",\"children\":[{\"path\":\"/auth/admin\"," +
                        "\"name\":\"账号管理\",\"index\":\"2-1\",\"icon\":\"Avatar\",\"component\":\"Admin\"" +
                        "}, {\"path\":\"/auth/group\",\"name\":\"菜单管理\"," +
                        "\"index\":\"2-2\",\"icon\":\"Menu\",\"component\":\"Group\"}" +
                        "]},{\"path\":\"vppz\",\"name\":\"陪诊管理\",\"index\":\"3\"," +
                        "\"icon\":\"BellFilled\",\"children\":[{\"path\":\"/vppz/order\"," +
                        "\"name\":\"订单管理\",\"index\":\"3-1\",\"icon\":\"List\",\"component\":\"Order\"" +
                        "}" +
                        "]}]}";
                break;
            case "1,2,4,5,3,6,7":
                route = "{\"path\":\"/\",\"component\":\"Main\",\"name\":\"主页\",\"children\":[{\"" +
                        "path\":\"/dashboard\",\"name\":\"控制台\",\"index\":\"1\",\"icon\":\"Platform\"," +
                        "\"component\":\"Dashboard\"},{\"path\":\"/auth\",\"name\":\"权限管理\","+
                        "\"index\":\"2\",\"icon\":\"Grid\",\"children\":[{\"path\":\"/auth/admin\"," +
                        "\"name\":\"账号管理\",\"index\":\"2-1\",\"icon\":\"Avatar\",\"component\":\"Admin\"" +
                        "}, {\"path\":\"/auth/group\",\"name\":\"菜单管理\"," +
                        "\"index\":\"2-2\",\"icon\":\"Menu\",\"component\":\"Group\"}" +
                        "]},{\"path\":\"vppz\",\"name\":\"陪诊管理\",\"index\":\"3\"," +
                        "\"icon\":\"BellFilled\",\"children\":[{\"path\":\"/vppz/order\"," +
                        "\"name\":\"订单管理\",\"index\":\"3-1\",\"icon\":\"List\",\"component\":\"Order\"" +
                        "},{\"path\":\"/vppz/staff\",\"name\":\"陪护管理\"," +
                        "\"index\":\"3-2\",\"icon\":\"Checked\",\"component\":\"Staff\"}" +
                        "]}]}";
                break;
            default:
                route="{\"path\":\"/\",\"component\":\"Main\",\"name\":\"主页\",\"children\":[" +
                        "{\"path\":\"/auth\",\"name\":\"权限管理\","+
                        "\"index\":\"2\",\"icon\":\"Grid\",\"children\":[{\"path\":\"/auth/admin\"," +
                        "\"name\":\"账号管理\",\"index\":\"2-1\",\"icon\":\"Avatar\",\"component\":\"Admin\"" +
                        "}, {\"path\":\"/auth/group\",\"name\":\"菜单管理\"," +
                        "\"index\":\"2-2\",\"icon\":\"Menu\",\"component\":\"Group\"}" +
                        "]}]}";
                break;
        }
        return Result.success(route, "OK");

    }
}
